import Vue from "vue";
import VueRoute from "vue-router";
// 一级路由
import Home from "../views/Home";
import Login from "../views/Login";

// 二级路由
import New from "../views/Home/components/New";
import Game from "../views/Home/components/Game";
import Movie from "../views/Home/components/Movie";



Vue.use(VueRoute);

// 重写$router的push方法，让本身的后两个参数 有默认值
const reslut = VueRoute.prototype.push;
VueRoute.prototype.push = function (
  location,
  onComplete = () => { },
  onAbort = () => { }) {
  reslut.call(this, location, onComplete, onAbort,);
};
// 重写router的replace方法，让本身的后两个参数 有默认值
const reslut1 = VueRoute.prototype.replace;
VueRoute.prototype.replace = function (
  location,
  onComplete = () => { },
  onAbort = () => { }) {
  reslut1.call(this, location, onComplete, onAbort,);
};

export default new VueRoute({
  //设置路由模式为history模式!!!!
  mode: "history",
  routes: [
    {
      path: "/home",
      component: Home,
      //如果当前的路由设置有默认子路由,则不建议书写name命名路由
      // name: "Home",
      // 配置默认子路由
      redirect: "/home/new",
      // 二级路由
      children: [
        {
          path: "new",
          component: New,
          name: "news"
        },
        {
          path: "game",
          component: Game,
          name: "game"
        },
        {
          path: "movie",
          component: Movie,
          name: "movie"
        }
      ]
    },
    {
      path: "/login",
      component: Login
    },
    // 默认路由
    {
      path: "/",
      // 重定向的配置
      redirect: "/home"
    }
  ]
});